package com.shiva.oms.logview.api.view;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import org.apache.commons.lang.StringUtils;

import com.shiva.oms.logview.domain.QueryCond;

/**
 * 
 * 描述：
 * 
 * <pre>
 * HISTORY
 * ****************************************************************************
 *  ID    DATE            PERSON            REASON
 *  1     2018年5月1日         YC           Create
 * ****************************************************************************
 * </pre>
 * 
 * @author YC
 * @version 1.0
 */
public class QueryGui extends JDialog {

    private final JPanel contentPanel = new JPanel();
    private JTextField textField;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        try {
            QueryGui dialog = new QueryGui();
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            dialog.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Create the dialog.
     */
    public QueryGui() {
        this(null, null);
    }

    public QueryGui(JFrame parent, QueryCond queryCond) {
        super(parent, true);
        setTitle("模糊查询");
        setBounds(100, 100, 499, 135);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(contentPanel, BorderLayout.CENTER);
        contentPanel.setLayout(null);

        JLabel label = new JLabel("模糊查询");
        label.setFont(new Font("微软雅黑", Font.PLAIN, 12));
        label.setBounds(21, 37, 54, 15);
        contentPanel.add(label);

        textField = new JTextField();
        textField.setBounds(82, 34, 309, 21);
        contentPanel.add(textField);
        textField.setColumns(10);

        JButton button = new JButton("查询");
        button.setFont(new Font("微软雅黑", Font.PLAIN, 12));
        button.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                if (StringUtils.isNotBlank(textField.getText())) {
                    queryCond.setKeyword(textField.getText());
                    setVisible(false);
                }
            }
        });
        button.setBounds(401, 33, 72, 23);
        contentPanel.add(button);
    }
}
